function oneFun() {
  i = 0;
  setInterval(function() {
    console.log("aaa=" + new Date());
    i++;
    if(i == 3) {
      clearInterval(this);
    }
  },1000);
  console.log("oneFun");
}
function twoFun() {
  j=0;
  setInterval(function() {
    console.log("bbb=" + new Date());
    j++;
    if(j == 3) {
      clearInterval(this);
    }
  },1000);
  console.log("oneFun执行完毕");
}
//oneFun();
//twoFun();

var async = require('async')
function exec1() {
  //async.series({....}); // 串行无关联
  //async.parallel({...}); // 并行无关联
  async.series({
    one: function(done) {
      i=0;
      setInterval(function() {
        console.log("aaa=" + new Date());
        i++;
        if(i == 3) {
          clearInterval(this);
          done(null, 'one 完毕');
        }
      },1000);
    },
    two: function(done) {
      j=0;
      setInterval(function() {
        console.log("bbb=" + new Date());
        j++;
        if(j == 3) {
          clearInterval(this);
          done(null, 'two 完毕');
        }
      },1000);
    },
    function(err,rs) {
      //console.log(err);
      //console.log(rs);
    }
  });
}

function exec2() {
  //async.waterfall({...}); // 串行有关联
  async.waterfall([
    function(preValue,done) {
      i=0;
      setInterval(function() {
        console.log("aaa=" + new Date());
        i++;
        if(i == 3) {
          clearInterval(this);
          done(null, preValue + ',one 完毕');
        }
      },1000);
    },
    function(preValue,done) {
      j=0;
      setInterval(function() {
        console.log("bbb=" + new Date());
        j++;
        if(j == 3) {
          clearInterval(this);
          done(null, preValue + ',two 完毕');
        }
      },1000);
    }],
    function(err,rs) {
      //console.log(err);
      //console.log(rs);
    }
  );
}

exec2();
console.log("主进程执行完毕");
